layui.use(['form','jquery','jquery_cookie','upload'], function () {
    var upload = layui.upload;
    upload.render({
        elem: '#fileBtn',
        url: ctx + '/user/updatePersonalById',
        accept: 'file',
        auto: false,
        bindAction: '#uploadBtn',
        done: function(res){
            if (res.code === 200){
                $("input[name='user_img']").val(res.result);
                layer.msg("文件上传成功！");
            }
        },
        error:function (res) {
            layer.msg("文件上传失败！");
            layer.msg(res.msg,{icon:5});
        }
    });

    var form = layui.form,
        layer = layui.layer,
        $ = layui.jquery,
        $ = layui.jquery_cookie($);

    form.on('submit(saveBtn)',function (data) {
        //所有表单元素的值
        console.log(data.field);
        //发送ajax请求
        $.ajax({
            type:"post",
            url:ctx + "/user/updateUserInfo",
            dataType:"json",
            data:{
                userName:data.field.user_name,
                trueName:data.field.true_name,
                email:data.field.user_email,
                phone:data.field.user_phone,
                userImg:data.field.user_img
            },
            success:function (result) {
                //判断是否修改成功
                if (result.code === 200){
                    //修改密码成功后，清空cookie数据，跳转到登录页面
                    layer.msg("基本资料修改成功！",function () {
                        //跳转到登录页面
                        window.parent.location.href = ctx + "/main";
                    })
                }else {
                    layer.msg(result.msg,{icon:5});
                }
            }
        });
    });
});